package com.luoke.service.request.impl;

import com.luoke.connect.GameWebSocketClient;
import com.luoke.context.UserContext;
import com.luoke.service.request.BattleRoundRequestService;
import com.luoke.manage.threadmanage.FutureManager;

import java.util.Scanner;
import java.util.concurrent.CompletableFuture;

public class BattleRoundRequestServiceImpl implements BattleRoundRequestService {

    boolean isFirstTurn = true; // 新增的标志，用于判断是否是第一回合
    public void startTurn(Scanner scanner, GameWebSocketClient gameWebSocketClient) {



        CompletableFuture<Object> turnFuture = new CompletableFuture<>();
        FutureManager.registerFuture(UserContext.getCurrentUser(), turnFuture);

//        // 如果是第一回合，直接执行回合逻辑，不用等待 `CompletableFuture` 的触发
//        if (isFirstTurn) {
//            isFirstTurn = false; // 标志为false，确保之后的回合走正常流程
//            executeTurn(opponentName);
//        } else {
//            // 否则等待 `CompletableFuture` 的完成再执行回合
//            turnFuture.thenRun(() -> executeTurn(opponentName));
//        }
    }

//    // 独立的回合执行方法
//    private void executeTurn(String opponentName) {
//        Scanner scanner = new Scanner(System.in);
//        System.out.println("轮到你了！请选择行动 (attack/defend): ");
//        String action = scanner.nextLine();
//        int damage = "attack".equalsIgnoreCase(action) ? 10 : 0;
//
//        // 将选择的操作发送到服务器
//        Result result = new Result();
//        result.setModuleName(ModuleTypeConstant.BATTLE);
//        result.setCommand("PERFORM_ACTION");
//        result.setData(new InitiateBattleDTO(UserContext.getCurrentUser(), opponentName, action, damage));
//        send(JSONUtil.toJsonStr(result));
//
//        // 进入等待状态，等待对手完成回合
//        FutureManager.registerFuture(UserContext.getCurrentUser(), new CompletableFuture<>());
//    }




}
